<template>
  <div class="leftBar">
    <el-menu
      router
      :unique-opened="true"
      :collapse-transition="true"
      active-text-color="#409eff"
      background-color="#304156"
      class="el-menu-vertical-demo leftMenus"
      :collapse="store.state.isHiddenNav"
      text-color="#fff"
      :default-active="router.currentRoute.value.path"
    >
      <el-menu-item index="999" @click="router.push('/index')">
        <i class="iconfont homepage"></i><span>首页</span>
      </el-menu-item>
      <el-sub-menu
        v-for="item in menuList"
        :key="item.id"
        :index="item.id + ''"
      >
        <template #title>
          <i class="iconfont" :class="item.icon"></i>
          <span class="navText"> {{ item.title }}</span>
        </template>
        <el-menu-item-group>
          <template v-for="subItem in item.children" :key="subItem.id">
            <el-menu-item
              v-if="subItem.hidden === 0"
              :index="'/' + item.name + '/' + subItem.name"
            >
              <i class="iconfont" :class="subItem.icon"></i>
              <span>{{ subItem.title }}</span>
            </el-menu-item>
          </template>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
    <div class="right">
      <el-breadcrumb class="breadcrumb" separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-if="$route.meta.name !== '首页'">
          <router-link tag="a" :to="$route.meta.path">{{
            $route.meta.name
          }}</router-link>
        </el-breadcrumb-item>
        <el-breadcrumb-item v-if="$route.meta.name !== '首页'">{{
          $route.meta.childName
        }}</el-breadcrumb-item>
      </el-breadcrumb>

      <slot name="rightContent"></slot>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, toRefs, ref, computed } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
let store = useStore();
let router = useRouter();
let menuList = computed(() => {
  return store.getters.getNewMenus;
});
</script>

<style lang="less" scoped>
.el-menu-vertical-demo {
  min-height: calc(100vh - 70px);
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  min-height: calc(100vh - 70px);
  width: 250px;
}
.right {
  flex: 1;
  height: calc(100vh - 70px);
  overflow: auto;
}
.leftBar {
  display: flex;
}
.navText {
  width: 120px;
}

.breadcrumb {
  padding: 15px;
  border-bottom: 1px solid rgb(227, 221, 221);
}
</style>
